package com.magina.project.mgdb.controller;

import com.magina.project.mgdb.service.EventBusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassnName :EventBusController
 * @Author： Magina.Hu
 * @Date： 2019/5/6
 * @Description：
 * @Version: V1.0
 * Copyright (c) 2019-2020 .All rights reserved.
 */
@RestController
@RequestMapping("/eventBus")
public class EventBusController {

    @Autowired
    private EventBusService eventBusService;

    //同步
    @GetMapping("/testEventBus")
    public ResponseEntity testEventBus() throws Exception {
        Long initTime = System.currentTimeMillis();
        eventBusService.postEvent();
        return ResponseEntity.ok(String.format("耗时:%s",System.currentTimeMillis()-initTime));
    }

    //异步
    //https://www.liangzl.com/get-article-detail-19337.html
    @GetMapping("/asyncTestEventBus")
    public ResponseEntity asyncTestEventBus() throws Exception {
        Long initTime = System.currentTimeMillis();
        eventBusService.asyncPostEvent();
        return ResponseEntity.ok(String.format("耗时:%s",System.currentTimeMillis()-initTime));
    }
}
